package com.daryl.jcu_project1_creditscoreform;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class LoginPage extends Activity {
	
	String userName;
	String userPass;
	Button login;
	EditText userNameLogin;
	EditText userPassWord;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_page);
        
        //set previouspage value to zero
        methods md = new methods();
        md.editorShareIntPreferences(this,"previousPage1",0);
        md.editorShareIntPreferences(this,"previousPage2",0);
        md.editorShareIntPreferences(this,"previousPage3",0);
        md.editorShareIntPreferences(this,"previousPage4",0);
        
        //setting raion button int and string to zero
        SharedPreferences preferences = getSharedPreferences(
				"Mb4Me", 0);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putInt("dResidentStatusInt", 0);
        editor.putInt("dPostalAddDiffFromResidentAddInt", 0);
        editor.putInt("dPostalAddChangeLoanSettledInt", 0);
        editor.putInt("dPreviousAddInt", 0);
        editor.putInt("dEmploymentStatusInt", 0);
        editor.putInt("dPreviousEmploymentStatusInt", 0);
        
        editor.putString("dResidentStatus", null);
		editor.putString("dPostalAddDiffFromResidentAddBtn", null); 
		editor.putString("dPostalAddChangeWhenLoanSettledBtn", null); 
		editor.putString("dPreviousAddBtn", null); 
		editor.putString("dEmploymentStatus", null); 
		editor.putString("dPreviousEmploymentStatus", null);
		editor.putString("dTotalCostCalculated", "0");
		editor.putString("dTotalFundingCalculated", "0");
		Log.d("retriveValue", "login test 1 " + preferences.getString("dTotalCostCalculated", "0"));
        
		editor.commit();
        
		Log.d("retriveValue", "login test 2 " + preferences.getString("dTotalCostCalculated", "0"));
        //set thread policy
        if (android.os.Build.VERSION.SDK_INT > 9) {
        	StrictMode.ThreadPolicy policy = 
        		new StrictMode.ThreadPolicy.Builder().permitAll().build();
        	StrictMode.setThreadPolicy(policy);
        }
        
        
        
        userNameLogin = (EditText) findViewById (R.id.textbox_username);
        userPassWord = (EditText) findViewById (R.id.textbox_pw);
        login = (Button) findViewById (R.id.button_login);
        
        final Context context = this;
        login.setOnClickListener(new View.OnClickListener() {
        	
        	public void onClick(View v) {
        		
        	//set userNameLogin in variable class
        		userName = userNameLogin.getText().toString(); 
        		userPass= userPassWord.getText().toString();
        	  variables vb = new variables();
        	  vb.VuserNameLogin = userNameLogin.getText().toString();
        	 // System.out.println(" login name " + vb.userNameLogin);
        	 // System.out.println(" login name " + userName);
        	  //vb.loginPage(userName);
        	  
        	  //senddata class method
        	  methods md = new methods();
        	 // System.out.println("data sent detail11 " + userName + " " + userPass );
        	  md.postData(getApplicationContext(),userName, userPass);
        	  //System.out.println("data sent detail22 " + vb.userNameLogin + " " + userPassWord.getText().toString());
        	  
        	  //next page
        	  Intent intent = new Intent(context, Display_form_personal_details.class);
              startActivity(intent);
              
             
        	}
        });
        }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_login_page, menu);
        return true;
    }
    
    public void nextPage (View view){
    	Intent intent_next = new Intent (this, Display_form_personal_details.class);
    	startActivity(intent_next);
    }
    
 
    
    
}
